package com.intelligentcar.springboot.service.serverImpl;

import com.intelligentcar.springboot.bean.Vehicle;
import com.intelligentcar.springboot.mapper.LogMapper;
import com.intelligentcar.springboot.mapper.VehicleMapper;
import com.intelligentcar.springboot.service.VehicleServer;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class VehicleServerImpl implements VehicleServer {
    @Autowired
    private LogMapper logMapper;
    @Autowired
    private VehicleMapper vehicleMapper;

    //车辆表中新增车辆
    @Override
    public int vehicleadd(HttpServletRequest req,Vehicle vehicle) {
        req.getSession().setAttribute("userName","王五");
        String time =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        String logUser = req.getSession().getAttribute("userName").toString();
        logMapper.addLog(time,"新增",logUser,"新增车辆信息");
        return vehicleMapper.vehicleadd(vehicle);
    }

    // 查询车辆表中的所有车辆信息
    @Override
    public List<Vehicle> lookupvehicle(RowBounds rowBounds) {
        return vehicleMapper.lookupvehicle(rowBounds);
    }

    // 查询车辆表中的单条车辆信息
    @Override
    public List<Vehicle> queryvehicle(Vehicle vehicle,RowBounds rowBounds) {
        return vehicleMapper.queryvehicle(vehicle,rowBounds);
    }
    // 根据车号查询车辆表中的单条车辆信息
    @Override
    public List<Vehicle> queryvehicle1(Vehicle vehicle,RowBounds rowBounds) {
        return vehicleMapper.queryvehicle1(vehicle,rowBounds);
    }
    // 根据车号查询车辆表中的单条车辆信息
    @Override
    public List<Vehicle> queryvehicle2(Vehicle vehicle,RowBounds rowBounds) {
        return vehicleMapper.queryvehicle2(vehicle,rowBounds);
    }
    // 根据车号查询车辆表中的单条车辆信息
    @Override
    public List<Vehicle> queryvehicle3(Vehicle vehicle,RowBounds rowBounds) {
        return vehicleMapper.queryvehicle3(vehicle,rowBounds);
    }
    //修改车辆表的车辆信息
    @Override
    public int updatevehiclee( HttpServletRequest req,Vehicle vehicle) {
        req.getSession().setAttribute("userName","王五");
        String time =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        String logUser = req.getSession().getAttribute("userName").toString();
        logMapper.addLog(time,"修改",logUser,"修改车俩信息");
        return vehicleMapper.updatevehiclee(vehicle);
    }

    //删除车辆表的车辆信息
    @Override
    public int deletevegicle(HttpServletRequest req,Vehicle vehicle) {
        req.getSession().setAttribute("userName","王五");
        String time =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        String logUser = req.getSession().getAttribute("userName").toString();
        logMapper.addLog(time,"删除",logUser,"删除车俩信息");
        return vehicleMapper.deletevegicle(vehicle);
    }

    //查询车辆表中有多少个数据
    @Override
    public int count() {
        return vehicleMapper.count();
    }

    //查询车辆表中有多少个数据
    @Override
    public int count1(Vehicle vehicle) {
        return vehicleMapper.count1(vehicle);
    }
    //查询车辆表中有多少个数据
    @Override
    public int count2(Vehicle vehicle) {
        return vehicleMapper.count2(vehicle);
    }
    //查询车辆表中有多少个数据
    @Override
    public int count3(Vehicle vehicle) {
        return vehicleMapper.count3(vehicle);
    }
    //查询车辆表中有多少个数据
    @Override
    public int count4(Vehicle vehicle) {
        return vehicleMapper.count4(vehicle);
    }
    //查询车辆表中的所有车牌号
    @Override
    public List<Vehicle> selectvehicle() {
        return vehicleMapper.selectvehicle();
    }

}
